<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top:10px
  }
  .rank-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .btn {
    height: 33px;
  }
  .btn-export {
    float: left;
  }
  .btn-upload {
    float: left;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>销售管理员工排行</span>
    </div>
    <div class="line"></div>
    <rank-form
      class="rank-form"
      @on-success-valid="handleSubmit">
    </rank-form>
    <!-- <div class="btn">
      <btn-export :tableData="rankList" :tableTitle="columns" :title="title" class="btn-export"></btn-export>
      <btn-upload class="btn-upload" :title="title"></btn-upload>
    </div> -->
    <!-- <Button
      type="primary"
      @click="handleClick">
      生成当月统计报表
    </Button> -->
    <!-- <update-sale-modal
      @update-valid="handleUpdate">
    </update-sale-modal> -->
    <Table
      class="table"
      :columns="columns"
      :data="historyData"
      border>
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import {
  saveSaleRecord
} from '../../api/sale'
import RankForm from '_c/rank-form'
// import UpdateSaleModal from '_c/update-sale-modal'
import TablePage from '_c/page'
import BtnExport from '_c/btn-export'
import BtnUpload from '_c/btn-upload'
export default {
  components: {
    RankForm,
    // UpdateSaleModal,
    TablePage,
    BtnExport,
    BtnUpload
  },
  data () {
    return {
      id: '',
      state: '',
      page: 1,
      title: '销售管理员工排行',
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 60,
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '姓名',
          key: 'uname',
          align: 'center'
        },
        {
          title: '提交数',
          key: 'cpa',
          align: 'center'
        },
        {
          title: '到司数',
          key: 'cpv',
          align: 'center'
        },
        {
          title: '预约到司数',
          key: 'ycpv',
          align: 'center'
        },
        {
          title: '成交数',
          key: 'cps',
          align: 'center'
        },
        {
          title: '成交率(%)',
          key: 'cpsb',
          align: 'center'
        },
        {
          title: '时间',
          key: 'ctime',
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.ctime ? params.row.ctime : '-'
            )
          }
        }
        // {
        //   title: '操作',
        //   key: 'cz',
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small',
        //           ghost: 'ghost'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         },
        //         on: {
        //           click: () => {
        //             this.handleClick(params.row.id, params.row)
        //           }
        //         }
        //       }, '修改')
        //     ])
        //   }
        // }
      ]
    }
  },
  computed: {
    ...mapState({
      rankList: state => state.rank.rankList,
      dataCount: state => state.rank.rankDataCount,
      historyData: state => state.rank.rankHistoryData,
      pageSize: state => state.rank.pageSize
    })
  },
  methods: {
    ...mapActions([
      'getRankList',
      'updateModalState',
      'getRankCurrentRow',
      // 'updateSaleData',
      'changeRankPage'
    ]),
    handleSubmit (playload) {
      this.getRankList(playload)
    },
    changePage (index) {
      this.page = index
      this.changeRankPage(index)
      this.getRankList({ page: index })
    }
    // async saveRecord () {
    //   await saveSaleRecord()
    // },
    // handleClick (id, row) {
    //   let newRow = {}
    //   this.id = id
    //   if (row) {
    //     newRow = Object.assign({}, row)
    //   }
    //   this.getSaleRecordCurrentRow(newRow)
    //   this.updateModalState(true)
    // },
    // handleClick () {
    //   this.saveRecord()
    // }
    // handleUpdate (playload, id) {
    //   this.updateSaleData(playload).then(
    //     this.getSaleRecordList({})
    //   )
    //   this.updateModalState(false)
    // }
  },
  created () {
    this.getRankList({})
  }
}
</script>
